package com.atguigu.gmall.payment;

import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.alipay.api.response.AlipayTradePagePayResponse;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: lx
 * @Time: 11:41
 * @Description:
 */
public class PaymentDemo {

    //付款方（消费者）（同学们）     收款方（商家）（尚品汇）    支付宝（平台）   三方

    //连接支付宝微服务
    public static void main(String[] args) throws Exception{////支付宝公司 SDK 包  Apache HttpClient
        AlipayClient alipayClient = new DefaultAlipayClient(
                        "https://openapi.alipaydev.com/gateway.do",//支付宝平台接口的URL
                "2016102100732915",//收款方的帐户
                "MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCOMXA+L6a5S1VvvPTgYuIsn3pNdT016hthjr+X1cnj074diJsa+NDeYgt/to8phdxTq3oCb1pDou5p67J4kwgshwK/raHTXXKIYub2bvUaNxwU7lN2SMqBQajXA5q+FDjdYfOUbNtckY9IvcujUXlfxuUMnJPeQcfJWpmvCCvGxOfsyWfOr6PGpTDV3ClHmWoYoMKB/iY36K8prigCZSQfQ8IMQa1gtsGoazstHrzjto4X8V4QZFY/gUK6fzHqmTQzS36N5xmUwdE6DqiJs9uCddfr/S/t65vNAlzm0/KjK+kshqY9UtE9v2Xc3NCMDh2I/n56Rtnw9F/GWupVePtLAgMBAAECggEATrjKNnN1L2Kos0r+m3fDVgcY0+dTcxTgAdvg8LO4qTxiJcGqdX1JTcUkLpmomsl0WJI34z84zvdWXSfTT/O+87/vYqVDUVyL+zweOFLnuZLHJkNny7Wy/2qViiyBsDhL3yzKiOLXc2FW3WPOaOXDd6YKyzeomcT7Udup+ABjFBC7QttWERf192VP3DZGOdjRpFbhyi3ns+CZoCNSJFkP5xwNP6Wf2HdxYceh+IH0XzRE4yyZzidN1wD+to6wpoKR68o+PqdlOuFhtfuqnLcMdUouaVRAHAstBT4kAPHIpT+6moflOT1ajw3DVvaeJfUtSJRjjR/mlKWdB+k1ypi8oQKBgQDhs32YK06Ujl/xnULguOi76/5y2UIxeceOnsvcFQOCCdl9C6RpbXncXCUITb5fdsfdhL8E0lDmBe2NMP1H+psQRPGGKaY9qYDWJpZn+rHGFaZCr6NvAL9ctiU0LjjTKDZWkhTjG+PQpwi6L9EvmpSOxiWeONsOT+VngsSa9hV4uwKBgQChSBZtuVYLj/3K6YEHs3bABFe0MAHX0OqclSZ6+gYOX1vNjWy7tHnSgAjJw3xpd+gMu5Kb4oHJ6gL6iZbcTfcfvpkBUyVdMMhsgALZXfsY7edMkOhom95doyZxvxdyQ5OtNyH1IgzouUF3bHyPgTP+jXAwwcDGlJqYopjGSjJmsQKBgHFT2e1tWWCYeK5uI2WJEztAzRvH4UfMeRowu/X/CyrhXTY/gUd6s+Sk0+duefefQc4F2JBINly5f0UU4yigOfoaVBfkk9eEY++jooQFSfxHZJs5a9vRyUR5JQclal0EZPxlD13V5Dchl+09E1FO0ec6sSrYK43tKigmbifNBoz/AoGAOP9Z9dMPBq0Pmztkf008RWYDfMmOjS/nCgln/QQJSeEHd6Bocfm5J9xZvrxYZomat40+pdqp1are/J3Nc/QVxuE7/4zb4pBP9JBU8W7WQ5woJxX7HKUhM+RpvL800Qvyz79xP8mV2FVIPqVXa/vUXTytDn4a29M+w3yLE2C7aTECgYB3AUTVEKptCt4B0O71BL4T6fxyhJDWs5ocY+6elygii5O7vc23tzgmbx/Jrm+VKcJvx1o2qhZ9HeVL7171XdpHdXzH06j8ArDQhZB1HPXjDLDqyj2pQ/jeSdBP0abbFO9jXQvh65i6Wy4/PcQL8vP8+5jB6O8DK2zQM0Gzonj1dQ==",//收款方 私钥
                "json",//
                "UTF-8",//
                "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAv4FgjWsfvbXEkzs5T+z5r4X9m5Qh8OA0zlZA3T9yeCqlcRRqydMBfRsB4V9aHUH0KCV875mzF7Feh3VoDilcDpGtuKo5l7YRVnGSyQTq0pQjMFYi/wKGFGHAA37Wl2L/AMaGpT6CJncSqcAJssY61qmz/o9lw+hRq6KBfdktl4xm0d5f+uMgCLKqa6bYbFyG7vNZszGJ6yW2n6fFbZ0B4PgPXfrRFVG+OS204bi7sGDba6DuJPPuk8B/gkVoDkmKHNRnLXZi74jyZROlEXKr8JElZqpT6RODkKAmIRCGlQrAadUntgmymguRlN2K+TfSNIigY1FRekb/BudYhlbA5QIDAQAB",//支付宝公钥
                "RSA2");//RSA2 加密方式 三个外国人  号称全世界最安全加密方式
        AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
        Map map = new HashMap<>();
        map.put("out_trade_no","tyreuyrggjyhtdggh6y5rtk7dsafas");
        map.put("product_code","FAST_INSTANT_TRADE_PAY");
        map.put("total_amount","10");
        map.put("subject","我要买手机");

        request.setBizContent(JSONObject.toJSONString(map));
        AlipayTradePagePayResponse response = alipayClient.pageExecute(request);
        if(response.isSuccess()){

            String body = response.getBody();//
            System.out.println(body);
            System.out.println("调用成功");
        } else {
            System.out.println("调用失败");
        }

/*        <form name="punchout_form" method="post"
action="https://openapi.alipaydev.com/gateway.do?charset=UTF-8&method=alipay.trade.page.pay&sign=e2oXOyOm1Vzv769BdRLagcUbbTCS5iBmiQpawO7Sb5UN32grIf7eKaZgw%2BzQ%2FeYCIiW7qRDc%2B2wqMDvfpsXuGpsyfiK%2BKwqdMHXE6RFsiGbqG2a6AvzMCdGYFatBHNXcCOSNxzZBeONb9MwNJKe7Tdj27%2B9Tcr%2BABL1vnAFbQNYa7RfB4CUY%2BhmTj0pViM9%2FOPvhat4t2qOuwh%2BVOWfZvSay9%2BXPqFoOUiJj0925RWoEDmvaRWZBEOKvyTPxw3qG%2FSCNeL1h2e3LVe%2BWelyB9B1dMwkobscJvAZC4qsWJxXrQkJgkersTrilJtcQTGnQjLnh2nh5N8o%2BxhmqxTEP7w%3D%3D&version=1.0&app_id=2016102100732915&sign_type=RSA2&timestamp=2021-01-11+14%3A31%3A11&alipay_sdk=alipay-sdk-java-4.8.73.ALL&format=json">
<input type="hidden" name="biz_content" value="{&quot;out_trade_no&quot;:&quot;tyreuyrggjyhtdggh6y5rtk7dsafas&quot;,&quot;total_amount&quot;:&quot;10&quot;,&quot;subject&quot;:&quot;我要买手机&quot;,&quot;product_code&quot;:&quot;FAST_INSTANT_TRADE_PAY&quot;}">
<input type="submit" value="立即支付" style="display:none" >
</form>
<script>document.forms[0].submit();</script>*/



    }
}
